import CustomerDetailDrawer from './unDoListDetailDrawer.vue';
import { h, render, App } from 'vue';

const createMount = (app: App, opt: any) => {
  const mountNode = document.createElement('div');
  document.body.appendChild(mountNode);
  const vnode = h(CustomerDetailDrawer, {
    ...opt,
    remove() {
      document.body.removeChild(mountNode);
    },
  });

  // 将vnode 的上下文指向当前的app的上下文
  vnode.appContext = app._context;
  render(vnode, mountNode);
};

const Modal = {
  install(app: App) {
    app.config.globalProperties.$CustomerDetailDrawer = {
      show: (options = {} as any) => {
        options.id = options.id || 'customer_detail_' + 1;
        createMount(app, options);
      },
    };
  },
};

export default Modal;
